package com.config;

import com.service.impl.UserServiceImplDetail;
import com.util.AuthenticationProviderUtil;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

@Configuration
public class SecurityConfig {//extends WebSecurityConfigurerAdapter

    @Resource
    private AuthenticationProviderUtil authenticationProviderUtil;

    @Resource
    private UserServiceImplDetail userServiceImplDetail;

    /*@Override
    protected void configure(HttpSecurity http) throws Exception {
        http
            .exceptionHandling().accessDeniedPage("/errors")
            .and()
            .authorizeRequests()
//            .antMatchers("/index").hasAuthority("USER")
            .antMatchers("/signIn", "/doLogin", "/errors").permitAll() // 将不需要认证的路径明确指定
            .antMatchers("/**").authenticated()
            .and()
            .formLogin()
            .loginPage("/signIn")
            .loginProcessingUrl("/doLogin")
            .defaultSuccessUrl("/getUserList")
            .permitAll();
    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        super.configure(auth);
        auth.authenticationProvider(authenticationProviderUtil);
        auth.userDetailsService(userServiceImplDetail).passwordEncoder(passwordEncoder());
        *//*BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        String encode = bCryptPasswordEncoder.encode("123");
        auth.inMemoryAuthentication()
                .withUser("zs").password(encode).roles("role1");*//*
    }

    @Bean
    public PasswordEncoder passwordEncoder() {
        return new BCryptPasswordEncoder();
    }

    @Override
    public void configure(WebSecurity web) throws Exception {
        web.ignoring().antMatchers("/resources/**"); // 忽略静态资源
    }*/
}
